import {Component, Injector, OnInit} from '@angular/core';
import {EmployeeServiceSvr} from '../../../services/employee.service';
import {ResumeMgeSvr} from '../../../services/resume-mge-svr.service';
import {CoreComponent} from 'pengesoft-ng-lib';
import {Resume} from '../../../domains/resume.domain';
@Component({
  selector: 'app-personnelchanges',
  templateUrl: './personnelchanges.component.html',
  styleUrls: ['./personnelchanges.component.less']
})
export class PersonnelchangesComponent extends CoreComponent implements OnInit {

  // tslint:disable-next-line:max-line-length
  listOfDataPersonChange: { jobId: any; skay: number; phone: any; name: any; id: any }[] = [];

  state = '';
  staffDate = new Resume();

  constructor(private injector: Injector,
              private employSvr: EmployeeServiceSvr,
              private resumeMgeSvr: ResumeMgeSvr) {
    super(injector);
  }

  ngOnInit(): void {
    this.queryList(5);
  }

  // 按状态查员工花名册
  queryEmployeeByState( state ): any{
    this.employSvr.myGetEmployeeDtoByState( state ).then(res => {
      this.listOfDataPersonChange = this.dealTYX(res);
      return this.listOfDataPersonChange;
    });
  }

  // 查询员工状态表
  queryList(state: number): void {
    this.resumeMgeSvr.getDetailList(new Resume({ApplyStatus: state})).then(res => {
      this.listOfDataPersonChange = this.dealData(res);
      return this.listOfDataPersonChange;
    });
  }

  changeData(state): void {
    this.state = state;
    this.listOfDataPersonChange = state === '待入职' ? this.queryList(5) : this.queryEmployeeByState(state);
  }

  // 数据处理
  dealData(res): any {
    return res.map((item, index) => {
      return {
        skay: index + 1,
        phone: item.Resume.Tel,
        name: item.Resume.Name,
        id: item.Resume.Id,
        jobId: item.Resume.JobId,
        Email: item.Resume.Email,
        Education: item.Resume.Education,
        Remarks: item.Resume.Remarks,
        InfoSource: item.Resume.InfoSource,
        JobName: item.JobName,
      };
    });
  }

  // 处理唐英熊返回给我的
  dealTYX(res): any {
    return res.map((items, index) => {
      const sex = items.Employee.sex === 0 ? '男' : '女';
      return {
        skay: index + 1,
        phone: items.Employee.Phone,
        name: items.Employee.Name,
        id: items.Employee.Id,
        department: items.DeptName,
        jobId: items.Employee.JobId,
        ResumeFile: items.Employee.ResumeFile,
        ApplyStatus: items.Employee.ApplyStatus,
        ApplyType: items.Employee.ApplyType,
        ApplyWay: items.Employee.ApplyWay,
      };
    });
  }

}
